package Mapper.Admin;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.LocalDateTime;

import static pojo.Mysql.*;

public class huoDongFaBuMapper {
    public void insert(String name, String huodong) {
        try (Connection connection = DriverManager.getConnection(url, user, dbPassword)) {
            String query = "INSERT INTO huodongfabu (name,createtime, neirong) " +
                    "VALUES (?, ?, ?)";

            try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
                preparedStatement.setString(1, name);
                preparedStatement.setObject(2, LocalDateTime.now()); // 使用当前时间
                preparedStatement.setString(3, huodong);

                int rowsAffected = preparedStatement.executeUpdate();
                if (rowsAffected > 0) {
                    System.out.println("数据添加成功！");
                } else {
                    System.out.println("数据添加失败！");
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
